import { type Chain, getDefaultConfig } from '@rainbow-me/rainbowkit';
import {
  backpackWallet,
  baseAccount,
  berasigWallet,
  bestWallet,
  bifrostWallet,
  binanceWallet,
  bitgetWallet,
  bitskiWallet,
  bitverseWallet,
  bloomWallet,
  bybitWallet,
  clvWallet,
  coin98Wallet,
  compassWallet,
  coreWallet,
  dawnWallet,
  desigWallet,
  enkryptWallet,
  foxWallet,
  frameWallet,
  frontierWallet,
  gateWallet,
  imTokenWallet,
  iopayWallet,
  kaiaWallet,
  kaikasWallet,
  krakenWallet,
  kresusWallet,
  ledgerWallet,
  magicEdenWallet,
  metaMaskWallet,
  mewWallet,
  nestWallet,
  novaWallet,
  oktoWallet,
  okxWallet,
  omniWallet,
  oneInchWallet,
  oneKeyWallet,
  paraSwapWallet,
  phantomWallet,
  rabbyWallet,
  rainbowWallet,
  readyWallet,
  ramperWallet,
  roninWallet,
  safeWallet,
  safeheronWallet,
  safepalWallet,
  subWallet,
  tahoWallet,
  talismanWallet,
  tokenPocketWallet,
  tokenaryWallet,
  trustWallet,
  uniswapWallet,
  valoraWallet,
  walletConnectWallet,
  wigwamWallet,
  ctrlWallet,
  xPortalWallet,
  zealWallet,
  zerionWallet,
  zilPayWallet,
  universalProfilesWallet,
} from '@rainbow-me/rainbowkit/wallets';
import { publicActions } from 'viem';
import {
  apeChain,
  arbitrum,
  arbitrumSepolia,
  avalancheFuji,
  base,
  baseSepolia,
  berachain,
  berachainTestnetbArtio,
  blast,
  blastSepolia,
  bsc,
  bscTestnet,
  curtis,
  degen,
  gnosis,
  gravity,
  holesky,
  ink,
  inkSepolia,
  linea,
  lineaSepolia,
  lukso,
  mainnet,
  monadTestnet,
  optimism,
  optimismSepolia,
  polygon,
  polygonMumbai,
  sanko,
  scroll,
  scrollSepolia,
  sepolia,
  superposition,
  unichain,
  unichainSepolia,
  zksync,
  zora,
  zoraSepolia,
} from 'wagmi/chains';

const projectId =
  process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ?? 'YOUR_PROJECT_ID';

// Configure Base Account
baseAccount.subAccounts = {
  creation: 'on-connect',
  defaultAccount: 'sub',
  funding: 'spend-permissions',
};

baseAccount.preference = {
  attribution: { auto: true },
};

// Configure MetaMask analytics
metaMaskWallet.enableAnalytics = false;

const avalanche = {
  id: 43_114,
  name: 'Avalanche',
  iconUrl: 'https://s2.coinmarketcap.com/static/img/coins/64x64/5805.png',
  iconBackground: '#fff',
  nativeCurrency: { name: 'Avalanche', symbol: 'AVAX', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://api.avax.network/ext/bc/C/rpc'] },
  },
  blockExplorers: {
    default: { name: 'SnowTrace', url: 'https://snowtrace.io' },
  },
  contracts: {
    multicall3: {
      address: '0xca11bde05977b3631167028862be2a173976ca11',
      blockCreated: 11_907_934,
    },
  },
} as const satisfies Chain;

export const config = getDefaultConfig({
  appName: 'RainbowKit Demo',
  projectId,
  walletConnectParameters: {
    telemetryEnabled: false,
  },
  chains: [
    mainnet,
    base,
    optimism,
    arbitrum,
    polygon,
    apeChain,
    avalanche,
    berachain,
    blast,
    bsc,
    degen,
    gravity,
    ink,
    sanko,
    superposition,
    unichain,
    zora,
    linea,
    gnosis,
    scroll,
    zksync,
    lukso,
    ...(process.env.NEXT_PUBLIC_ENABLE_TESTNETS === 'true'
      ? [
          sepolia,
          holesky,
          arbitrumSepolia,
          avalancheFuji,
          baseSepolia,
          berachainTestnetbArtio,
          blastSepolia,
          bscTestnet,
          curtis,
          inkSepolia,
          lineaSepolia,
          monadTestnet,
          optimismSepolia,
          polygonMumbai,
          scrollSepolia,
          unichainSepolia,
          zoraSepolia,
        ]
      : []),
  ],
  wallets: [
    {
      groupName: 'Popular',
      wallets: [
        safeWallet,
        rainbowWallet,
        baseAccount,
        metaMaskWallet,
        walletConnectWallet,
      ],
    },
    {
      groupName: 'Other',
      wallets: [
        readyWallet,
        backpackWallet,
        berasigWallet,
        bestWallet,
        bifrostWallet,
        binanceWallet,
        bitgetWallet,
        bitskiWallet,
        bitverseWallet,
        bloomWallet,
        bybitWallet,
        clvWallet,
        coin98Wallet,
        compassWallet,
        coreWallet,
        dawnWallet,
        desigWallet,
        enkryptWallet,
        foxWallet,
        frameWallet,
        frontierWallet,
        gateWallet,
        imTokenWallet,
        iopayWallet,
        kaiaWallet,
        kaikasWallet,
        krakenWallet,
        kresusWallet,
        ledgerWallet,
        magicEdenWallet,
        mewWallet,
        nestWallet,
        novaWallet,
        oktoWallet,
        okxWallet,
        omniWallet,
        oneInchWallet,
        oneKeyWallet,
        paraSwapWallet,
        phantomWallet,
        rabbyWallet,
        ramperWallet,
        roninWallet,
        safeheronWallet,
        safepalWallet,
        subWallet,
        tahoWallet,
        talismanWallet,
        tokenPocketWallet,
        tokenaryWallet,
        trustWallet,
        uniswapWallet,
        universalProfilesWallet,
        valoraWallet,
        wigwamWallet,
        ctrlWallet,
        xPortalWallet,
        zealWallet,
        zerionWallet,
        zilPayWallet,
      ],
    },
  ],
  ssr: true,
});

export const publicClient = config.getClient().extend(publicActions);
